<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  
  <title>Hexo</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <meta name="description" content="第二章 控制结构与异常处理控制结构 分支结构  if  案例求解一元二次方程 import java.util.Date;import java.text.DecimalFormat;public class Exam2_1{ public static void getRoot(double a,double b,double c) &amp;#123;     if(a!&#x3D;0)     &amp;#123;">
<meta property="og:type" content="article">
<meta property="og:title" content="Hexo">
<meta property="og:url" content="https://goofyer.gitee.io/notes-on-computer-expertise/2021/12/20/Java/%E7%AC%AC%E4%BA%8C%E7%AB%A0%20%E6%8E%A7%E5%88%B6%E7%BB%93%E6%9E%84%E4%B8%8E%E5%BC%82%E5%B8%B8%E5%A4%84%E7%90%86/index.html">
<meta property="og:site_name" content="Hexo">
<meta property="og:description" content="第二章 控制结构与异常处理控制结构 分支结构  if  案例求解一元二次方程 import java.util.Date;import java.text.DecimalFormat;public class Exam2_1{ public static void getRoot(double a,double b,double c) &amp;#123;     if(a!&#x3D;0)     &amp;#123;">
<meta property="og:locale" content="en_US">
<meta property="article:published_time" content="2021-12-19T17:27:13.494Z">
<meta property="article:modified_time" content="2021-12-19T17:27:14.177Z">
<meta property="article:author" content="John Doe">
<meta name="twitter:card" content="summary">
  
    <link rel="alternate" href="/notes-on-computer-expertise/atom.xml" title="Hexo" type="application/atom+xml">
  
  
    <link rel="shortcut icon" href="/notes-on-computer-expertise/favicon.png">
  
  
    
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/typeface-source-code-pro@0.0.71/index.min.css">

  
  
<link rel="stylesheet" href="/notes-on-computer-expertise/css/style.css">

  
    
<link rel="stylesheet" href="/notes-on-computer-expertise/fancybox/jquery.fancybox.min.css">

  
<meta name="generator" content="Hexo 5.4.0"></head>

<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/notes-on-computer-expertise/" id="logo">Hexo</a>
      </h1>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/notes-on-computer-expertise/">Home</a>
        
          <a class="main-nav-link" href="/notes-on-computer-expertise/archives">Archives</a>
        
      </nav>
      <nav id="sub-nav">
        
          <a id="nav-rss-link" class="nav-icon" href="/notes-on-computer-expertise/atom.xml" title="RSS Feed"></a>
        
        <a id="nav-search-btn" class="nav-icon" title="Search"></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="https://goofyer.gitee.io/notes-on-computer-expertise"></form>
      </div>
    </div>
  </div>
</header>

      <div class="outer">
        <section id="main"><article id="post-Java/第二章 控制结构与异常处理" class="h-entry article article-type-post" itemprop="blogPost" itemscope itemtype="https://schema.org/BlogPosting">
  <div class="article-meta">
    <a href="/notes-on-computer-expertise/2021/12/20/Java/%E7%AC%AC%E4%BA%8C%E7%AB%A0%20%E6%8E%A7%E5%88%B6%E7%BB%93%E6%9E%84%E4%B8%8E%E5%BC%82%E5%B8%B8%E5%A4%84%E7%90%86/" class="article-date">
  <time class="dt-published" datetime="2021-12-19T17:27:13.494Z" itemprop="datePublished">2021-12-20</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
    <div class="e-content article-entry" itemprop="articleBody">
      
        <h2 id="第二章-控制结构与异常处理"><a href="#第二章-控制结构与异常处理" class="headerlink" title="第二章 控制结构与异常处理"></a>第二章 控制结构与异常处理</h2><h3 id="控制结构"><a href="#控制结构" class="headerlink" title="控制结构"></a>控制结构</h3><ul>
<li><p>分支结构</p>
<ul>
<li><p>if</p>
<ul>
<li><p>案例求解一元二次方程</p>
<p>import java.util.Date;<br>import java.text.DecimalFormat;<br>public class Exam2_1<br>{</p>
<pre><code>public static void getRoot(double a,double b,double c)
&#123;
    if(a!=0)
    &#123;
        double d=b*b-4*a*c;
        DecimalFormat df=new DecimalFormat(&quot;0.000&quot;);//

        if(d&gt;0)
        &#123;
            double x1=(-b+Math.sqrt(d))/(2*a);
            double x2=(-b-Math.sqrt(d))/(2*a);
            System.out.println(&quot;x1=&quot;+df.format(x1)+&quot; x2=&quot;+df.format(x2));
        &#125;
        if(d==0)
            System.out.println(&quot;x1=x2=&quot;+df.format(-b/(2*a)));

        else
        &#123;
            double real=-b/(2*a);
            double image=Math.sqrt(-d)/(2*a);
            System.out.println(&quot;x1=&quot;+df.format(real)+&quot;+&quot;+df.format(image));
            System.out.println(&quot;x2=&quot;+df.format(real)+&quot;-&quot;+df.format(image));
        &#125;
    &#125;
    else
    &#123;
        System.out.println(&quot;不是二次方程&quot;);
    &#125;
&#125;
public static void main(String args[])
&#123;
    getRoot(4,4,1);
    getRoot(1,5,6);
    getRoot(10,1,2);
    getRoot(0,2,3);
&#125;
</code></pre><p>}</p>
</li>
</ul>
</li>
<li><p>switch</p>
<ul>
<li><p>求下一天的日期</p>
<p>public class Exam2_2求下一天的日期<br>{</p>
<pre><code>public static void main(String args[])
&#123;
    int y,m,d;
    int dnum=0;
    boolean isLeap=false;
    Scanner scanner=new Scanner(System.in);
    String data=scanner.nextLine();
    String ymd[]=data.split(&quot;-&quot;);
    y=Integer.parseInt(ymd[0]);
    m=Integer.parseInt(ymd[1]);
    d=Integer.parseInt(ymd[2]);
    if(y&lt;1000||y&gt;9999||m&lt;1||m&gt;12)
    &#123;
        System.out.println(&quot;日期不合法&quot;);
        return;
    &#125;
    if((y%400==0)||(y%4==0&amp;&amp;y%100!=0))
    &#123;
        isLeap=true;
    &#125;

    switch(m)
    &#123;
        case 1:
        case 3:
        case 5:
        case 7:
        case 8:
        case 10:
        case 12:
            dnum=31;
            break;
        case 2:
            if(isLeap)
            &#123;
                dnum=29;
            &#125;
            else
                dnum=28;
            break;
        case 4:
        case 6:
        case 9:
        case 11:
            dnum=30;
            break;
    &#125;

    if(d&lt;1||d&gt;dnum)
    &#123;
        System.out.println(&quot;日期不合法&quot;);
        return;
    &#125;

    if(d!=dnum)
    &#123;
        d++;
    &#125;
    else
    &#123;
        if(m==12)
        &#123;
            y++;
            m=1;
            d=1;
        &#125;
        else
        &#123;
            m++;
            d=1;
        &#125;
    &#125;
    System.out.println(y+&quot;-&quot;+m+&quot;-&quot;+d);

&#125;
</code></pre><p>}</p>
</li>
</ul>
</li>
</ul>
</li>
<li><p>循环结构</p>
<ul>
<li><p>for</p>
<ul>
<li><p>求素数</p>
<p>public class Exam2_3求素数<br>{</p>
<pre><code>public static boolean isprim(int num)
&#123;
    for(int j=num-1;j&gt;1;j--)
    &#123;
        if(num%j==0)
            return false;
    &#125;
    return true;
&#125;

public static void main(String args[])
&#123;
    for(int i=2;i&lt;101;i++)
    &#123;
        if(isprim(i))
            System.out.println(i);
    &#125;
&#125;
</code></pre><p>}</p>
</li>
</ul>
</li>
<li><p>while</p>
<ul>
<li><p>sin、</p>
<p>public class Exam2_4sinx<br>{</p>
<pre><code>public static double f1(double x)
&#123;
    double s=0;
    double t=x;
    int n=0;
    while(Math.abs(t)&gt;=0.0001)
    &#123;
        s=s+t;
        t=(-1)*t*x*x/((n+1)*(n+2));
        n=n+2;
    &#125;
    return s;
&#125;
public static void main(String args[])
&#123;
    System.out.println(f1(2));
    System.out.println(Math.sin(2));
&#125;
</code></pre><p>}</p>
</li>
<li><p>进制转换</p>
<p>public class Exam2_5进制转换<br>{</p>
<pre><code>public static double f1(double x)
&#123;
    double s=0;
    double t=x;
    int n=0;
    while(Math.abs(t)&gt;=0.0001)
    &#123;
        s=s+t;
        t=(-1)*t*x*x/((n+1)*(n+2));
        n=n+2;
    &#125;
    return s;
&#125;
public static void main(String args[])
&#123;
    System.out.println(f1(2));
    System.out.println(Math.sin(2));
&#125;
</code></pre><p>}</p>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<h3 id="异常处理"><a href="#异常处理" class="headerlink" title="异常处理"></a>异常处理</h3><ul>
<li><p>异常及其体系</p>
<ul>
<li><p>编译错误</p>
<ul>
<li>没有遵循语言的规则，有编译程序检查发现</li>
</ul>
</li>
<li><p>运行错误</p>
<ul>
<li>环境中发现一个不可执行的操作</li>
</ul>
</li>
<li><p>逻辑错误</p>
<ul>
<li>程序没有按预期的方案执行</li>
</ul>
</li>
</ul>
</li>
<li><p>throwable</p>
<ul>
<li><p>Exception</p>
<ul>
<li><p>IOException</p>
<ul>
<li>FileNotFoundException</li>
<li>EOFException</li>
</ul>
</li>
<li><p>AWTException</p>
</li>
<li>ClassNotFoundException</li>
<li><p>interruptedException</p>
<ul>
<li>java.lang.Object 类的 wait 方法</li>
<li>java.lang.Thread 类的 sleep 方法</li>
<li>java.lang.Thread 类的 join 方法</li>
</ul>
</li>
<li><p>RunTimeException不需要程序员进行捕获处理</p>
<ul>
<li><p>IndexOutOfBoundsException</p>
<ul>
<li>ArrayIndexOutOfBoundsException</li>
</ul>
</li>
<li><p>ArthrnetieException</p>
</li>
<li>NullPointerException</li>
<li><p>IllegalArgumentrException</p>
<ul>
<li>NumberFormatException</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li><p>Error 是系统出错，catch是无法处理的，难以修复的</p>
<ul>
<li>virtualmachineerror</li>
<li>awterror</li>
<li>linkageerror</li>
</ul>
</li>
</ul>
</li>
</ul>
<h3 id="异常处理机制"><a href="#异常处理机制" class="headerlink" title="异常处理机制"></a>异常处理机制</h3><ul>
<li><p>java采用一个相对简单的统一的抛出和处理机制 堆栈传递解决</p>
<ul>
<li><p>1.try和catch语句</p>
<ul>
<li>●将要处理的代码放入try块中，然后创建相应的catch块的列表。如果生成都异常与catch中提到的相匹配，那么catch条件中的块语句就被执行。try块后可能有许多catch块，每个都处理不同的异常。每个catch中的参数都是Exception的子类。</li>
</ul>
</li>
<li><p>2.finally语句</p>
<ul>
<li>●finally语句定义一个总是执行的代码，而不考虑异常是否被捕获。</li>
</ul>
</li>
<li><p>3.throw引起一个异常</p>
<ul>
<li>‍●‍‍调用申明抛出异常</li>
<li>●‍throw语句强制抛出异常</li>
</ul>
</li>
</ul>
</li>
<li><p>整数的算术运算</p>
<p>public static void main(String args[])</p>
<pre><code>&#123;
    int x,y;
    int result=0;
    String op;
    try
    &#123;
        Scanner scanner=new Scanner(System.in);
        x=scanner.nextInt();
        op=scanner.next();
        y=scanner.nextInt();
        if(op.equals(&quot;+&quot;))
        &#123;
            result=x+y;
        &#125;
        else if(op.equals(&quot;-&quot;))
        &#123;
            result=x-y;
        &#125;
        else if(op.equals(&quot;*&quot;))
        &#123;
            result=x*y;
        &#125;
        else if(op.equals(&quot;/&quot;))
        &#123;
            result=x/y;
        &#125;
        else 
        &#123;
            throw new Exception();
        &#125;
        System.out.println(x+op+y+&quot;=&quot;+result);
    &#125;
    catch(InputMismatchException ex)
    &#123;
        System.out.println(&quot;数据错误&quot;);
    &#125;
    catch(ArithmeticException ex)
    &#123;
        System.out.println(&quot;除零错误&quot;);
    &#125;
    catch(Exception ex)
    &#123;
        System.out.println(&quot;运算甫错误&quot;);
    &#125;
&#125;
</code></pre><p>}</p>
</li>
<li><p>求三角形面积</p>
<p>class IllegalDataException extends Exception<br>{</p>
<pre><code>public IllegalDataException()
&#123;
    super(&quot;数据无效&quot;);
&#125;
public IllegalDataException(String s)
&#123;
    super(s);
&#125;
</code></pre><p>}<br>class MyApp<br>{</p>
<pre><code>public double area(float a,float b,float c)throws IllegalDataException
&#123;
    if(a+b&gt;c&amp;&amp;a+c&gt;b&amp;&amp;b+c&gt;a)
    &#123;
        float p=(a+b+c)/2;
        return Math.sqrt(p*(p-a)*(p-b)*(p-c));
    &#125;
    else
    &#123;
        throw new IllegalDataException(&quot;三角形数据错误&quot;);
    &#125;
&#125;
</code></pre><p>}<br>public class Exam2_7求三角形面积<br>{</p>
<pre><code>public static void main(String args[])
&#123;
    MyApp myapp=new MyApp();
    try
    &#123;
        double f1=myapp.area(3,4,5);
        System.out.println(f1);
        double f2=myapp.area(3,4,1);
        System.out.println(f2);
    &#125;
    catch(IllegalDataException ex)
    &#123;
        System.out.println(ex);
    &#125;
&#125;
</code></pre><p>}</p>
</li>
</ul>

      
    </div>
    <footer class="article-footer">
      <a data-url="https://goofyer.gitee.io/notes-on-computer-expertise/2021/12/20/Java/%E7%AC%AC%E4%BA%8C%E7%AB%A0%20%E6%8E%A7%E5%88%B6%E7%BB%93%E6%9E%84%E4%B8%8E%E5%BC%82%E5%B8%B8%E5%A4%84%E7%90%86/" data-id="cl403sxra001nf8vu4ws890ne" data-title="" class="article-share-link">Share</a>
      
      
      
    </footer>
  </div>
  
    
<nav id="article-nav">
  
    <a href="/notes-on-computer-expertise/2021/12/20/Java/%E7%AC%AC%E4%B8%89%E7%AB%A0%20%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1%E7%BC%96%E7%A8%8B/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Newer</strong>
      <div class="article-nav-title">
        
          (no title)
        
      </div>
    </a>
  
  
    <a href="/notes-on-computer-expertise/2021/12/20/Java/%E7%AC%AC%E4%B8%80%E7%AB%A0%20%E5%BC%95%E8%A8%80/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Older</strong>
      <div class="article-nav-title"></div>
    </a>
  
</nav>

  
</article>


</section>
        
          <aside id="sidebar">
  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Categories</h3>
    <div class="widget">
      <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/notes-on-computer-expertise/categories/C-%E5%B7%A5%E5%85%B7/">C#工具</a></li><li class="category-list-item"><a class="category-list-link" href="/notes-on-computer-expertise/categories/C-%E5%B7%A5%E5%85%B7/">C++工具</a></li><li class="category-list-item"><a class="category-list-link" href="/notes-on-computer-expertise/categories/Mysql/">Mysql</a></li><li class="category-list-item"><a class="category-list-link" href="/notes-on-computer-expertise/categories/blender/">blender</a></li><li class="category-list-item"><a class="category-list-link" href="/notes-on-computer-expertise/categories/linux/">linux</a></li><li class="category-list-item"><a class="category-list-link" href="/notes-on-computer-expertise/categories/manim/">manim</a></li><li class="category-list-item"><a class="category-list-link" href="/notes-on-computer-expertise/categories/spring/">spring</a></li><li class="category-list-item"><a class="category-list-link" href="/notes-on-computer-expertise/categories/vba%E5%9F%BA%E7%A1%80%E6%93%8D%E4%BD%9C/">vba基础操作</a></li><li class="category-list-item"><a class="category-list-link" href="/notes-on-computer-expertise/categories/%E5%88%9B%E9%80%A0%E6%A8%A1%E5%BC%8F/">创造模式</a></li><li class="category-list-item"><a class="category-list-link" href="/notes-on-computer-expertise/categories/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F/">操作系统</a></li><li class="category-list-item"><a class="category-list-link" href="/notes-on-computer-expertise/categories/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F%E5%9F%BA%E7%A1%80%E7%9F%A5%E8%AF%86/">操作系统基础知识</a></li><li class="category-list-item"><a class="category-list-link" href="/notes-on-computer-expertise/categories/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F%E5%BC%80%E5%8F%91/">操作系统开发</a></li><li class="category-list-item"><a class="category-list-link" href="/notes-on-computer-expertise/categories/%E6%95%B0%E5%AD%A6/">数学</a></li><li class="category-list-item"><a class="category-list-link" href="/notes-on-computer-expertise/categories/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84/">数据结构</a></li><li class="category-list-item"><a class="category-list-link" href="/notes-on-computer-expertise/categories/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E5%9F%BA%E7%A1%80%E7%9F%A5%E8%AF%86/">数据结构基础知识</a></li><li class="category-list-item"><a class="category-list-link" href="/notes-on-computer-expertise/categories/%E6%A8%A1%E6%9D%BF/">模板</a></li><li class="category-list-item"><a class="category-list-link" href="/notes-on-computer-expertise/categories/%E6%B7%B1%E5%BA%A6%E5%AD%A6%E4%B9%A0/">深度学习</a></li><li class="category-list-item"><a class="category-list-link" href="/notes-on-computer-expertise/categories/%E8%8B%B1%E8%AF%AD/">英语</a></li><li class="category-list-item"><a class="category-list-link" href="/notes-on-computer-expertise/categories/%E8%99%9A%E5%B9%BB4/">虚幻4</a></li><li class="category-list-item"><a class="category-list-link" href="/notes-on-computer-expertise/categories/%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%BB%84%E6%88%90%E5%8E%9F%E7%90%86/">计算机组成原理</a></li><li class="category-list-item"><a class="category-list-link" href="/notes-on-computer-expertise/categories/%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%BD%91%E7%BB%9C/">计算机网络</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tags</h3>
    <div class="widget">
      <ul class="tag-list" itemprop="keywords"><li class="tag-list-item"><a class="tag-list-link" href="/notes-on-computer-expertise/tags/C/" rel="tag">C++</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tag Cloud</h3>
    <div class="widget tagcloud">
      <a href="/notes-on-computer-expertise/tags/C/" style="font-size: 10px;">C++</a>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Archives</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/notes-on-computer-expertise/archives/2022/05/">May 2022</a></li><li class="archive-list-item"><a class="archive-list-link" href="/notes-on-computer-expertise/archives/2022/03/">March 2022</a></li><li class="archive-list-item"><a class="archive-list-link" href="/notes-on-computer-expertise/archives/2022/02/">February 2022</a></li><li class="archive-list-item"><a class="archive-list-link" href="/notes-on-computer-expertise/archives/2022/01/">January 2022</a></li><li class="archive-list-item"><a class="archive-list-link" href="/notes-on-computer-expertise/archives/2021/12/">December 2021</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Recent Posts</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/notes-on-computer-expertise/2022/05/31/vue/%E5%89%8D%E7%AB%AF%E6%A1%86%E6%9E%B6%E9%AA%8C%E8%AF%81%E7%A0%81%E6%97%A0%E6%B3%95%E6%98%BE%E7%A4%BA/">(no title)</a>
          </li>
        
          <li>
            <a href="/notes-on-computer-expertise/2022/05/26/%E6%95%B0%E6%8D%AE%E5%BA%93/navicat%E5%AE%89%E8%A3%85/">(no title)</a>
          </li>
        
          <li>
            <a href="/notes-on-computer-expertise/2022/05/25/%E8%99%9A%E5%B9%BB4%E5%BC%95%E6%93%8E%E5%BC%80%E5%8F%91/%E8%99%9A%E5%B9%BB%E5%9B%9B%20mod%E5%88%B6%E4%BD%9C/">(no title)</a>
          </li>
        
          <li>
            <a href="/notes-on-computer-expertise/2022/05/23/python/python%E6%89%B9%E9%87%8F%E7%94%9F%E6%88%90%E6%95%B0%E6%8D%AE/">(no title)</a>
          </li>
        
          <li>
            <a href="/notes-on-computer-expertise/2022/05/23/vba%E5%9F%BA%E7%A1%80%E6%93%8D%E4%BD%9C%E7%AC%94%E8%AE%B0/EXCEL%E5%9F%BA%E7%A1%80%E6%95%99%E7%A8%8B/">(no title)</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      
      &copy; 2022 John Doe<br>
      Powered by <a href="https://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>

    </div>
    <nav id="mobile-nav">
  
    <a href="/notes-on-computer-expertise/" class="mobile-nav-link">Home</a>
  
    <a href="/notes-on-computer-expertise/archives" class="mobile-nav-link">Archives</a>
  
</nav>
    


<script src="/notes-on-computer-expertise/js/jquery-3.4.1.min.js"></script>



  
<script src="/notes-on-computer-expertise/fancybox/jquery.fancybox.min.js"></script>




<script src="/notes-on-computer-expertise/js/script.js"></script>





  </div>
<script type="text/x-mathjax-config">
    MathJax.Hub.Config({
        tex2jax: {
            inlineMath: [ ["$","$"], ["\\(","\\)"] ],
            skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code'],
            processEscapes: true
        }
    });
    MathJax.Hub.Queue(function() {
        var all = MathJax.Hub.getAllJax();
        for (var i = 0; i < all.length; ++i)
            all[i].SourceElement().parentNode.className += ' has-jax';
    });
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-MML-AM_CHTML"></script>
</body>
</html>